package com.wd.jetpack.demo.main

import android.view.View
import com.wd.jetpack.R
import com.wd.jetpack.base.BaseActivity
import com.wd.jetpack.databinding.ActivityDemoMainBinding
import com.wd.jetpack.demo.main.fragment.DemoMainFragment
import com.wd.jetpack.demo.main.vm.DemoMainViewModel
import com.wd.jetpack.util.FragmentUtils

/**
 * NA<BR>
 *
 * @author w4425
 * @version [V5.9.3, 2021/6/18]
 * @since V5.9.3
 */
class DemoMainActivity : BaseActivity<ActivityDemoMainBinding>() {
    //    private var elapsedTime = 0L
    private val mVm: DemoMainViewModel by lazy { DemoMainViewModel() }
    override fun getLayoutId(): Int {
        return R.layout.activity_demo_main
    }

    override fun initView() {
        mBinding.vm = mVm
        lifecycle.addObserver(mBinding.chronometerTime)
    }

    override fun initData() {
        /**
         * fragmentManager manager = getSupportFragmentManager()
         * FragmentTransaction transaction = manager.beginTransaction()
         * transaction.add(id,fragment)
         * transaction.commit()
         * Kotlin添加Fragment
         * 消除beginTransaction() and commit()方法  如果在开发中少写了一个commit()方法，或许会花费大量时间进行调试找到问题所在
         *
         */

        FragmentUtils.replaceFragment(supportFragmentManager, R.id.fragmentLayout, DemoMainFragment.newInstance())
    }

    override fun onClick(v: View) {
    }

//    override fun onResume() {
//        super.onResume()
//        mBinding.chronometerTime.base = SystemClock.elapsedRealtime() - elapsedTime
//        mBinding.chronometerTime.start()
//    }
//
//    override fun onPause() {
//        super.onPause()
//        elapsedTime = SystemClock.elapsedRealtime() - mBinding.chronometerTime.base
//        mBinding.chronometerTime.stop()
//    }
}